package com.kaiwukj.android.ufamily.mvp.ui.page.service.gm;

import android.widget.ImageView;

import com.blankj.utilcode.util.LogUtils;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.kaiwukj.android.ufamily.R;
import com.kaiwukj.android.ufamily.mvp.browse.JBrowseImgActivity;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;

public class GMProjectImagePreviewAdapter extends BaseQuickAdapter<String, BaseViewHolder> {
    public GMProjectImagePreviewAdapter(@Nullable List<String> data) {
        super(R.layout.item_gm_order_detail_project_image, data);
        LogUtils.d("size----------------------->" + data.size());
    }

    @Override
    public int getItemCount() {
        return Math.min(super.getItemCount(), 9);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder holder, String s) {
        Glide.with(getContext())
                .load(s)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .placeholder(R.drawable.picture_image_placeholder)
                .into((ImageView) holder.getView(R.id.iv_image));

        holder.getView(R.id.iv_image).setOnClickListener(v -> {
            JBrowseImgActivity.start(getContext(), new ArrayList<>(getData()), holder.getAdapterPosition(), null, v);
        });

        if (hasMore()) {
            holder.setVisible(R.id.container_bg, holder.getAdapterPosition() == 9 - 1);
        }

    }

    private boolean hasMore() {
        return getData().size() > 9;
    }
}
